using System;
using System.Collections.Generic;
using System.Linq;

namespace Kiwi.Container.DependencyInjection
{
    public class AllProperties : IEnumerateDependentProperties
    {
        #region IEnumerateDependentProperties Members

        public IEnumerable<IDependentProperty> EnumerateDependentProperties(object instance,
                                                                            Func<Type, bool> isValidType)
        {
            return instance.GetType()
                .GetProperties()
                .Where(p => isValidType(p.PropertyType))
                .Where(p => p.CanRead && p.CanWrite)
                .Where(p => p.GetIndexParameters().Length == 0)
                .Select(p => new DependentProperty(instance, p))
                .Cast<IDependentProperty>();
        }

        #endregion
    }
}